Shader "Unlit/Wxy法线贴图+渐变纹理"
{
    Properties
    {
        _MainTex ("主纹理", 2D) = "white" {}
        _GradientTex("渐变纹理", 2D) = "white" {}
        _DiffuseColor("漫反射颜色", Color) = (1, 1, 1, 1)
        _SpecularClolor("高光颜色", Color) = (1, 1, 1, 1)
        _SpecularScale("高光强度", Range(0, 10)) = 1
    }
    SubShader
    {
        Tags
        {
            "LightMode"="ForwardBase"
        }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #include "Lighting.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float4 texcoord : TEXCOORD0;
                float4 tangent : TANGENT;
            };

            struct v2f
            {
                float4 pos : SV_POSITION;
                float3 normal : TEXCOORD0;
                float2 uv : TEXCOORD1;
                float3 viewDir : TEXCOORD2;
                float3 worldPos : TEXCOORD3;
                float2 gradientUV : TEXCOORD4;
            };

            sampler2D _MainTex;
            sampler2D _GradientTex;
            float4 _MainTex_ST;
            float4 _GradientTex_ST;
            float4 _DiffuseColor;
            float4 _SpecularClolor;
            float _SpecularScale;

            v2f vert(appdata v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                
                o.normal = UnityObjectToWorldNormal(v.normal);
                o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
                o.gradientUV = TRANSFORM_TEX(v.texcoord, _GradientTex);
                o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                o.viewDir = _WorldSpaceCameraPos - o.worldPos;
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                //纹理
                fixed4 texColor = tex2D(_MainTex, i.uv);
                float3 viewDir = normalize(i.viewDir);
                float3 lightDir = normalize(_WorldSpaceLightPos0 - i.worldPos);
                float3 halfDir = normalize(viewDir + lightDir);
                float diffuseIntensity = dot(i.normal, lightDir) * 0.5 + 0.5;
                float specularIntensity = pow(max(0, dot(i.normal, halfDir)), _SpecularScale);
                fixed4 ambientColor = UNITY_LIGHTMODEL_AMBIENT * _DiffuseColor;
                fixed4 diffuseColor = tex2D(_GradientTex, fixed2(diffuseIntensity, diffuseIntensity)) * texColor *_LightColor0;
                fixed4 specularColor = _LightColor0 * texColor * specularIntensity;
                fixed4 finalColor = ambientColor + diffuseColor + specularColor;
                return finalColor;
            }
            ENDCG
        }
    }
}